// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var base = require("base");
	var databind = require("databind");
	var _css = require("./login.css");
	var sid="";
	var tools = require("tools");
	
	var init = function() {
		base.clearData("sid");
		sid = base.getUrlParam("sessionUuid");
		if (sid != null && sid != "") {
			base.saveData("sid", sid); //存sessionUuid
			base.saveData("appKey", "FINANCE-ENTERPRISE-WEB"); //存appkey
			tools.existPermission("yirunCube_1", function(){
				layer.msg("登陆成功");
				location.href = "../main/main.html";
			}, function(){
				layer.msg("该账号暂无查看一润魔方权限,请联系管理员!");
			});
		}
		initEvent();
	};
	var initEvent = function() {
		//		登陆
		$(".loginSubmit").unbind("click").click(function(){
//			layer.msg("登陆成功");
			login($("input[name=username]").val(), $("input[name=password]").val());
		});
	};
	
	//登陆
	var login = function(mUsername, mPassword) {
		base.fnAjax({
			action: "userNameLogin.json",
			async: false,
			nocode: true,
			oData: {
				username: mUsername,
				password: mPassword,
				appKey: "FINANCE-PLATFORM-WEB"
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.saveData("sid", data.datas[0].sessionUuid); //存sessionUuid
					base.saveData("appKey", "FINANCE-PLATFORM-WEB"); //存appkey
					base.saveData("tenantId", data.datas[0].tenantId); //存accountId
					tools.existPermission("yirunCube_1", function(){
						layer.msg("登陆成功");
//						location.href = "../main/main.html";
						location.href = "../new/yirun.html";
					}, function(){
						layer.msg("该账号暂无查看一润魔方权限,请联系管理员!");
					});
//					alert(tools.existPermission("yirunCube_1"));
//					location.href = "../main/main.html"
				} else {
					layer.msg(data.message);
				}
			}
		});
	};

	return {
		init: init
	};
});